﻿using ServiceOperater.ViewModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;

namespace ServiceOperater.Templates
{
    // Service, Action数据源时模板的选择
    [Obsolete("未使用")]
    public sealed class SaTemplateSelector : DataTemplateSelector
    {
        public override System.Windows.DataTemplate SelectTemplate(object item, System.Windows.DependencyObject container)
        {
            if (null == item)
            {
                return ((FrameworkElement)container).FindResource("defaultTemplate") as DataTemplate; ;
            }

            Window win = Application.Current.MainWindow;
            //当前正在显示的是ServiceTreeNodeViewModel类数据时：
            if (item is ServiceTreeNodeViewModel)
            {
                ServiceTreeNodeViewModel p = item as ServiceTreeNodeViewModel;
                return ((FrameworkElement)container).FindResource("serviceTemplate") as DataTemplate;
            }
            else if (item is ActionTreeNodeViewModel)
            {
                ActionTreeNodeViewModel a = item as ActionTreeNodeViewModel;
                return ((FrameworkElement)container).FindResource("actionTemplate") as DataTemplate;

            }
            return null;
        }
    }


    /* 失败, 不过注意ContentControl,除了设置ContentTemplateSelector,还要设置Content="{Binding}"
     
     
     <ContentControl Grid.Column="2" Content="{Binding}"  DataContext="{Binding  SelectedItem, ElementName=serviceTree}">
            <ContentControl.Resources>
                <DataTemplate  x:Key="defaultTemplate">
                    <Grid>
                        <TextBlock>NoThing</TextBlock>
                    </Grid>
                </DataTemplate>
                <DataTemplate DataType="{x:Type vm:ServiceTreeNodeViewModel}" x:Key="serviceTemplate">
                    <ItemsControl Grid.Column="2" ItemsSource="{Binding ActionChildren}">
                        <Expander ExpandDirection="Down">
                            <Expander.Style>
                                <Style TargetType="Expander">
                                    <Setter Property="IsExpanded" Value="{Binding IsExpanded, Mode=TwoWay}"></Setter>
                                </Style>
                            </Expander.Style>
                            <Expander.Header>
                                <TextBlock Text="{Binding Name}" FontWeight="Bold"/>
                            </Expander.Header>
                            <Expander.Content>
                                <Grid>
                                    <Grid.RowDefinitions>
                                        <RowDefinition/>
                                        <RowDefinition/>
                                        <RowDefinition/>
                                        <RowDefinition/>
                                        <RowDefinition/>
                                        <RowDefinition/>
                                        <RowDefinition/>
                                        <RowDefinition/>
                                        <RowDefinition/>
                                    </Grid.RowDefinitions>
                                    <Grid.ColumnDefinitions>
                                        <ColumnDefinition Width="30*"></ColumnDefinition>
                                        <ColumnDefinition Width="70*"></ColumnDefinition>
                                    </Grid.ColumnDefinitions>
                                    <TextBlock Grid.Row="0" Text="name"></TextBlock>
                                    <TextBlock Grid.Row="1"  Text="sqlId"></TextBlock>
                                    <TextBlock Grid.Row="2"  Text="sqlType"></TextBlock>
                                    <TextBlock Grid.Row="3"  Text="result"></TextBlock>
                                    <TextBlock Grid.Row="4"  Text="resultType"></TextBlock>
                                    <TextBlock Grid.Row="5"  Text="isPage"></TextBlock>
                                    <TextBlock Grid.Row="6"  Text="handler"></TextBlock>
                                    <TextBlock Grid.Row="7"  Text="parameter"></TextBlock>
                                    <TextBlock Grid.Row="8"  Text="condition"></TextBlock>

                                    <TextBox Grid.Row="0" Grid.Column="1"  Text="{Binding Name}"></TextBox>
                                    <TextBox Grid.Row="1" Grid.Column="1"  Text="{Binding SqlId}"></TextBox>
                                    <TextBox Grid.Row="2" Grid.Column="1"  Text="{Binding SqlType}"></TextBox>
                                    <TextBox Grid.Row="3" Grid.Column="1"  Text="{Binding Result}"></TextBox>
                                    <TextBox Grid.Row="4" Grid.Column="1"  Text="{Binding ResultType}"></TextBox>
                                    <TextBox Grid.Row="5" Grid.Column="1"  Text="{Binding IsPage}"></TextBox>
                                    <TextBox Grid.Row="6" Grid.Column="1"  Text="{Binding Handler}"></TextBox>
                                    <TextBox Grid.Row="7" Grid.Column="1"  Text="{Binding Parameter}"></TextBox>
                                    <TextBox Grid.Row="8" Grid.Column="1"  Text="{Binding Condition}"></TextBox>
                                </Grid>
                            </Expander.Content>
                        </Expander>

                    </ItemsControl>
                </DataTemplate>
                <DataTemplate DataType="{x:Type vm:ActionTreeNodeViewModel}" x:Key="actionTemplate">
                    <Expander ExpandDirection="Down">
                        <Expander.Style>
                            <Style TargetType="Expander">
                                <Setter Property="IsExpanded" Value="{Binding IsExpanded, Mode=TwoWay}"></Setter>
                            </Style>
                        </Expander.Style>
                        <Expander.Header>
                            <TextBlock Text="{Binding Name}" FontWeight="Bold"/>
                        </Expander.Header>
                        <Expander.Content>
                            <Grid>
                                <Grid.RowDefinitions>
                                    <RowDefinition/>
                                    <RowDefinition/>
                                    <RowDefinition/>
                                    <RowDefinition/>
                                    <RowDefinition/>
                                    <RowDefinition/>
                                    <RowDefinition/>
                                    <RowDefinition/>
                                    <RowDefinition/>
                                </Grid.RowDefinitions>
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="30*"></ColumnDefinition>
                                    <ColumnDefinition Width="70*"></ColumnDefinition>
                                </Grid.ColumnDefinitions>
                                <TextBlock Grid.Row="0" Text="name"></TextBlock>
                                <TextBlock Grid.Row="1"  Text="sqlId"></TextBlock>
                                <TextBlock Grid.Row="2"  Text="sqlType"></TextBlock>
                                <TextBlock Grid.Row="3"  Text="result"></TextBlock>
                                <TextBlock Grid.Row="4"  Text="resultType"></TextBlock>
                                <TextBlock Grid.Row="5"  Text="isPage"></TextBlock>
                                <TextBlock Grid.Row="6"  Text="handler"></TextBlock>
                                <TextBlock Grid.Row="7"  Text="parameter"></TextBlock>
                                <TextBlock Grid.Row="8"  Text="condition"></TextBlock>

                                <TextBox Grid.Row="0" Grid.Column="1"  Text="{Binding Name}"></TextBox>
                                <TextBox Grid.Row="1" Grid.Column="1"  Text="{Binding SqlId}"></TextBox>
                                <TextBox Grid.Row="2" Grid.Column="1"  Text="{Binding SqlType}"></TextBox>
                                <TextBox Grid.Row="3" Grid.Column="1"  Text="{Binding Result}"></TextBox>
                                <TextBox Grid.Row="4" Grid.Column="1"  Text="{Binding ResultType}"></TextBox>
                                <TextBox Grid.Row="5" Grid.Column="1"  Text="{Binding IsPage}"></TextBox>
                                <TextBox Grid.Row="6" Grid.Column="1"  Text="{Binding Handler}"></TextBox>
                                <TextBox Grid.Row="7" Grid.Column="1"  Text="{Binding Parameter}"></TextBox>
                                <TextBox Grid.Row="8" Grid.Column="1"  Text="{Binding Condition}"></TextBox>
                            </Grid>
                        </Expander.Content>
                    </Expander>
                </DataTemplate>
            </ContentControl.Resources>
            <!--P631-->
            <ContentControl.ContentTemplateSelector>
                <template:SaTemplateSelector/>
            </ContentControl.ContentTemplateSelector>
        </ContentControl>
     
     
     
     
     
     
     */
}
